
import  os
import gzip
from jsmin import jsmin

print("python script html create")
print(os.getcwd())
htmls=['index','config','update']
ln='\n'
html_h=f'#include <Arduino.h> \n'
for i in range(len(htmls)):
    html_gz=bytes()
    with open(f"./src/html/{htmls[i]}.html", "r", encoding="utf-8") as f:
        html_gz  =gzip.compress(jsmin(f.read()).encode("utf-8"))
    array_str='{'
    for j in range(len(html_gz)):
        if j%100==0:
            array_str=array_str+'\n' 
        array_str=array_str+str(int(html_gz[j]))+','
    array_str=array_str[0:-1]
    array_str=array_str+'\n};\n\n'
    html_h=html_h+f'#define {htmls[i].upper()}_LEN {len(html_gz)}{ln}const unsigned char {htmls[i]}_html[] = {array_str}'

with open("./src/html/html.h", "w", encoding="utf-8") as f:
    f.write(html_h)
